{include file="header.html"}
<script type="text/javascript">
//<!CDATA[
$(function(){
    // multi-select mall_gcategory
    $('#gcategory').length>0 && gcategoryInit("gcategory");
});
//]]>
</script>
<div id="rightTop">
  <p>会员列表</p>
</div>
<div class="mrightTop1 info">
  <div class="fontl">
    <form method="get" action="index.php?app=user&act=iframe">
      <input type="hidden" name="app" value="user" />
      <input type="hidden" name="act" value="iframe" />
     <select class="querySelect" name="field_name">{html_options options=$query_fields selected=$smarty.get.field_name}
          </select>
          <input class="queryInput" type="text" name="field_value" value="{$smarty.get.field_value|escape}" />
      <span style="position: relative; top: 5px;">
          <input type="submit" class="formbtn" value="{$lang.query}" />
          <a class="btn1" href="index.php?app=user&act=iframe">清空</a>
          <input type="button" class="formbtn" value="关闭" id="btn-close"/>
          <input type="button" class="formbtn" value="选择" id="btn-choose"/>
      </span>
    </form>
  </div>
  <div class="fontr">{include file=page.top.html}</div>
</div>
<div class="tdare">
  <table width="100%" cellspacing="0" class="dataTable">
    <!--{if $users}-->
    <tr class="tatr1">
       <td width="20" class="firstCell"><input type="checkbox" class="checkall" /></td>
      <td>{$lang.user_name} | {$lang.real_name}</td>
      <td><span ectype="order_by" fieldname="email">{$lang.email}</span></td>
      <td>{$lang.phone_mob}</td>
      <td>归属店铺</td>
      <td>注册途径</td>
      <td><span ectype="order_by" fieldname="reg_time">{$lang.reg_time}</span></td>
    </tr>
    <!--{/if}-->
    <!--{foreach from=$users item=user}-->
    <tr class="tatr2">
      <td class="firstCell">
        <input type="checkbox" class="checkitem" value="{$user.user_id}" attr-username="{$user.user_name}" attr-realname="{$user.real_name}" attr-email="{$user.email}" attr-phonemob="{$user.phone_mob}" attr-sname="{$user.s_name}" attr-refertype="{$user.refer_type}" value="{$user.user_id}"/>
      </td>
      <td>{$user.user_name|escape} | {$user.real_name|escape}</td>
      <td>{$user.email|escape}</td>
      <td>{$user.phone_mob|escape}</td>
      <td>{$user.s_name|escape}</td>
      <td>
        <!--{if $user.refer_type eq 1}-->
            分享注册
        <!--{elseif $user.refer_type eq 2}-->
            心愿单分享注册
        <!--{else}-->
            普通注册
        <!--{/if}-->
      </td>
      <td>{$user.reg_time|date:complete}</td>
    </tr>
    <!--{foreachelse}-->
    <tr class="no_data info">
      <td colspan="8">{$lang.no_data}</td>
    </tr>
    <!--{/foreach}-->
  </table>
  <!--{if $users}-->
  <div id="dataFuncs">
    <div class="pageLinks">{include file=page.bottom.html}</div>
   <!--{/if}-->
  </div>
  <div class="clear"></div>
</div>

<input id="user_id" name="user_id" style="display: none" value=''>

{include file="footer.html"}
<script>

  $("#btn-close").click(function () {
      window.parent.$('.bg-model').hide();
  })
  $("#btn-choose").click(function () {
      var items = '';
      var username = '';
      var realname = '';
      var email = '';
      var phone_mob = '';
      var refer_type = '';
      var s_name = '';

      //判断列表里是否有重复的数据
      var goods = window.parent.$("#user_id").val();
      var goodsArr = goods.split(',');
      var result = 1;

      $('.checkitem:checked').each(function(){
          if ($.inArray(this.value, goodsArr) >= 0) {
              if(result == 1){
                  var truthBeTold = window.confirm("您选择的用户有重复项，继续添加会去除重复项！")
                  result = 2;
                  return true;
              }
          }else{
              items += this.value + ',';
              username += $(this).attr('attr-username') + ','
              realname += $(this).attr('attr-realname') + ','
              email += $(this).attr('attr-email') + ','
              phone_mob += $(this).attr('attr-phonemob') + ','
              refer_type += $(this).attr('attr-refertype') + ','
              s_name += $(this).attr('attr-sname') + ','
          }
      });


      items = items.substr(0, (items.length - 1));
      username = username.substr(0, (username.length - 1));
      realname = realname.substr(0, (realname.length - 1));
      email = email.substr(0,(email.length - 1));
      phone_mob = phone_mob.substr(0,(phone_mob.length - 1));
      s_name = s_name.substr(0,(s_name.length - 1))

      var items_arr = items.split(',');
      var username_arr = username.split(',');
      var realname_arr = realname.split(',');
      var email_arr = email.split(',');
      var phone_mob_arr = phone_mob.split(',');
      var s_name_arr = s_name.split(',');


      if(!items){
          if(items_arr.length == 1){
              alert('该用户已存在列表中，请重新勾选用户！');
              return false;
          }
          alert('请勾选数据！');
          return false;
      }


      for(var i in items_arr){
          window.parent.$("#after").after('' +
              '<tr class="tatr1">' +
              '<td width="15%"><label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+username_arr[i]+'</label>' +
              '<td width="5%"><label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+email_arr[i]+'</label>' +
              '<td width="10%"><label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+phone_mob_arr[i]+'</label>' +
              '<td width="10%"><label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+s_name_arr[i]+'</label>' +
          '<td width="20%" class="table-center"><input type="checkbox" checked style="display: none" value="'+items_arr[i]+'" name="goods"><img style="margin-right: 10px;width:15px;height: 15px;" src="templates/style/images/close.gif" onclick="dropGoods(this' +
              ')" fieldname="mall_recommended" fieldid="{$goods.goods_id}" fieldvalue="1" title="{$lang.editable}"/></td></tr>');
      }
      window.parent.$('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(',');

      console.log(window.parent.$('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(','))

      window.parent.$('#user_id').val(window.parent.$('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(','));
      window.parent.$('.bg-model').hide();

  })


  function expEXCEL(url) {

  }

</script>